package com.cheetah.service.impl;

import com.cheetah.dto.UserDTO;
import com.cheetah.service.LoginOutService;
import com.cheetah.service.TokenService;
import com.cheetah.service.UserService;
import com.cheetah.utils.MapStructMapper;
import com.cheetah.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Administrator
 * @Date 2019/9/13
 * @Version V1.0
 * @Description:
 **/
@Component
public class LoginOutServiceImpl implements LoginOutService {

    @Autowired
    private MapStructMapper mapstructMapper;

    @Autowired
    private TokenService tokenService;

    @Autowired
    private UserService userService;

    @Override
    public UserDTO login(UserVO userVO) {

        userService.auth(userVO.getAccount(),userVO.getPassword());

        Map<String,Object> claims = new HashMap<>();
        claims.put("account",userVO.getAccount());
        claims.put("clientId",userVO.getClientId());
        claims.put("userAgent",userVO.getUserAgent());

        String token = tokenService.getToken(claims);

        return UserDTO.builder()
                .token(token)
                .build();
    }
}
